package org.example.test;

import org.junit.Test;

import java.io.InputStream;
import java.sql.*;
import java.util.Properties;

public class H2Base {


    @Test
    public void createTable() throws Exception {
        InputStream inputStream = H2Base.class.getResourceAsStream("/application.properties");
        Properties properties = new Properties();
        properties.load(inputStream);
        String driverClass = properties.getProperty("spring.h2.driverClass");
        String jdbcUrl = properties.getProperty("spring.h2.jdbcUrl");
        String username = properties.getProperty("spring.h2.username");
        String password = properties.getProperty("spring.h2.password");
        Class.forName(driverClass);

        String create_table_sql = "CREATE TABLE base_data (\n" +
                "\tid BIGINT(20) NOT NULL AUTO_INCREMENT,\n" +
                "\tval BLOB NOT NULL,\n" +
                "\tPRIMARY KEY (`id`)\n" +
                ")\n" +
                "COMMENT='基本的数据存储'\n" +
                "AUTO_INCREMENT=1";

        Connection connection = DriverManager.getConnection(jdbcUrl,username,password);
        Statement st = connection.createStatement();
        System.out.println(st.execute(create_table_sql));
    }
}
